//
//  E7HelpLayer.cpp
//  EndlessBattle
//
//  Created by cc on 12-5-7.
//  Copyright (c) 2012年 PalmGame. All rights reserved.
//

#include "E7HelpLayer.h"

#include "E7GameLayer.h"

CE7HelpLayer::CE7HelpLayer(CE7GameLayer* pParent)
{
    m_bIsAnimation = false ;

    m_bIsFlag = true ;
    m_nPageIndex = 0 ;
    m_nPageMax = 2 ;

    CCSize s = CCDirector::sharedDirector()->getWinSize() ;

//    setPosition(CCPointMake(s.width/2, s.height/2)) ;

    m_pBackColor = CCLayerColor::layerWithColorWidthHeight(ccc4(0, 0, 0, 255), s.width, s.height) ;
//    m_pBackColor->setPosition(CCPointZero) ;
    addChild(m_pBackColor) ;

    if (IsPad())
    {
        m_pHelpBack = CCSprite::spriteWithFile("back_dialog_help.png") ;
        m_pHelpPage[0] = CCSprite::spriteWithFile("page_help0.png") ;
        m_pHelpPage[1] = CCSprite::spriteWithFile("page_help1.png") ;
    }
    else
    {
        m_pHelpBack = CCSprite::spriteWithFile("back_dialog_help_iphone.png") ;
        m_pHelpPage[0] = CCSprite::spriteWithFile("page_help0_iphone.png") ;
        m_pHelpPage[1] = CCSprite::spriteWithFile("page_help1_iphone.png") ;
    }

    m_pHelpBack->setPosition(CCPointMake(s.width/2, s.height/2)) ;
    addChild(m_pHelpBack) ;

    m_pHelpPage[0]->setPosition(CCPointMake(s.width/2, s.height/2)) ;
    m_pHelpPage[1]->setPosition(CCPointMake(s.width/2, s.height/2)) ;

    for (int i = 0; i < m_nPageMax; ++i)
    {
        m_pHelpPage[i]->setIsVisible(false) ;
        addChild(m_pHelpPage[i]) ;
    }

    m_pHelpPage[0]->setIsVisible(true) ;
    setIsTouchEnabled(true) ;
    m_pParent = pParent ;
}

CE7HelpLayer::~CE7HelpLayer()
{
}

bool CE7HelpLayer::Loop()
{
    if (LS_STOP == GetStep())
    {
        return false ;
    }

    return true ;
}

void CE7HelpLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
{
    if (m_bIsFlag)
    {
        ++m_nPageIndex ;
        if (m_nPageIndex >= m_nPageMax)
        {
            Hide() ;
            return ;
        }
        for (int i = 0; i < m_nPageMax; ++i)
        {
            m_pHelpPage[i]->setIsVisible(false) ;
        }
        m_pHelpPage[m_nPageIndex]->setIsVisible(true) ;
    }
    else
    {
        Hide() ;
    }
}


void CE7HelpLayer::Show()
{
    if (m_bIsFlag)
    {
        m_nPageIndex = 0 ;
        for (int i = 0; i < m_nPageMax; ++i)
        {
            m_pHelpPage[i]->setIsVisible(false) ;
        }
        m_pHelpPage[0]->setIsVisible(true) ;
    }
    setIsVisible(true) ;
    setIsTouchEnabled(true) ;
}

void CE7HelpLayer::Hide()
{
    setIsVisible(false) ;
    setIsTouchEnabled(false) ;

    m_pParent->m_pZoomLayer->setIsTouchEnabled(true) ;
    m_pParent->setIsTouchEnabled(true) ;
}



























